<template>
  <div class="search-list" v-show="searches.length">
    <ul>
      <li class="search-item"
          v-for="(item,index) in searches"
          :key="index"
          @click.stop="addQuery(item)"
      >
        <span class="text">{{item}}</span>
        <span class="icon" @click.stop="deleteOne(item)">
              <i class="icon-delete"></i>
        </span>
      </li>
    </ul>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      searches: {
        type: Array,
        default: () => []
      }
    },
    methods: {
      // 点击搜索历史，进行搜索
      addQuery (item) {
        this.$emit('addQuery', item)
      },
      // 点击删除单个搜索历史
      deleteOne (item) {
        this.$emit('deleteOne', item)
      }
    }
  }
</script>

<style scoped lang="stylus">
  @import "~common/stylus/variable.styl"
  @import "~common/stylus/mixin.styl"
  .search-list
    .search-item
      display: flex
      align-items: center
      height: 40px
      overflow: hidden

      .text
        flex: 1
        color: $color-text-l

      .icon
        extend-click()

        .icon-delete
          font-size: $font-size-small
          color: $color-text-d
</style>
